1398F - Controversial Rounds - CodeForces Solution


binary search data structures dp greedy two pointers *2500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2000005;

int read()
{
	int f = 1, k = 0;
	char c = getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-')
		{
			f = -1;
		}
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		k = k * 10 + c - '0';
		c = getchar();
	}
	return f * k;
}

int n, m, k, tt, cnt, ans, pre[N][2];

string s;

signed main()
{
	scanf("%d", &n);
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		pre[i + 1][0] = pre[i][0];
		pre[i + 1][1] = pre[i][1];
		if (s[i] == '?')
		{
			continue;
		}
		pre[i + 1][s[i] & 1 ^ 1] = i + 1;
	}
	for (int len = 1; len <= n; len++)
	{
		int p = 0, ans = 0;
		while (p + len <= n)
		{
			if (pre[p + len][0] == pre[p][0] || pre[p + len][1] == pre[p][1])
			{
				p += len;
				ans++;
			}
			else
			{
				p = pre[p + len][pre[p + len][1] < pre[p + len][0]];
			}
		}
		cout << ans << " ";
	}
	return 0;
}

 	   	   			  				 	 			 				 	


Comments

Submit
0 Comments
More Questions

1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House